#include <iostream>
#include <vector>

void ReadInput (std::vector <int> &elements, int array_size) {
    for (int iteration = 0; iteration < array_size; ++iteration) {
        int element;
        std::cin >> element;
        elements.push_back(element);
    }
}

template <typename iterator_type>
void MaxInTheEnd (iterator_type begin, iterator_type end) {
    iterator_type max_element = begin;
    while (begin != end) {
        if (*max_element < *begin) {
            max_element = begin;
        }
        ++begin;
    }
    std::swap(*max_element, *(end - 1));
}

void PrintAnswer (std::vector <int> &answer) {
    for (auto element : answer) {
        std::cout << element << " ";
    }
}

int main() {
    int array_size;
    std::cin >> array_size;
    if (array_size == 0) {
        return 0;
    }
    std::vector <int> elements;
    ReadInput (elements, array_size);
    MaxInTheEnd (elements.begin(), elements.end());
    PrintAnswer (elements);
}
